package Leetcode.数组字符串;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName 最近人的最大距离
 * @since: 2023/8/23 13:55
 * @auth: kirito
 * @description:
 *
 **/
public class 最近人的最大距离 {
    public int maxDistToClosest(int[] seats) {
        int n = seats.length;
        int max=0;
        int res =0;
        for (int i = 0; i < n; i++) {
            if(seats[i]==1){
                res=0;
            }else{
                res++;
            }
            max = Math.max(max, res);
        }
        if(seats[n-1]==0){
            for(int j=n-1;j>=0;j--){
                if(seats[j]==1){
                    if(n-j-1>=max/2){
                        return n-j-1;
                    }
                    break;
                }

            }
        }
        if(seats[0]==0){
            for (int j = 0; j < n; j++) {
                if(seats[j]==1){
                    if(j>=max) {
                        return j;
                    }
                    break;
                }
            }
        }
        if(max%2==0){
            return max/2;
        }
        return max/2+1;
    }
    

}
